import pytest
from selenium import webdriver
from selenium.webdriver.common.by import By

from base.base_page import BasePage
from case1.Test_driver import TestOpenUrl
from pageobject.cxsq import Cxsq
from pageobject.login_page import page_login_object



class TestLogin:

    # @pytest.fixture(scope='Function', autouse=True)
    def test_open(self):
        global  driver
        driver = webdriver.Chrome()
        url="http://localhost:8083/ckw2016/"
        driver.get(url)

    # @pytest.mark.run(order=2)
    def test_selectFy_case01(self):

        page_login_object(driver).selecFy()

    """
        original_handle=driver.current_window_handle
        driver.find_element(By.XPATH,'//img[@onclick="selectFy();"]').click()
        for handle in driver.window_handles:
            if handle != original_handle:
                driver.switch_to.window(handle)

        driver.implicitly_wait(2)
        driver.find_element(By.XPATH,'//span[text()="江苏省南京市中级人民法院"]').click()
        driver.find_element(By.XPATH,'//input[@value="确定"]').click()
        driver.switch_to.window(original_handle)
    """

    # @pytest.mark.run(order=3)
    def test_login_case01(self):

        page_login_object(driver).login()
        # driver.find_element(By.ID, 'username').clear()
        # driver.find_element(By.ID, 'username').send_keys("0001")
        # driver.find_element(By.ID, 'password').clear()
        # driver.find_element(By.ID, 'password').send_keys("123")
        # driver.find_element(By.ID,'dl').click()

    def test_cxsq_case01(self):
        cxsq=Cxsq(driver)
        cxsq.intocxsq()
        cxsq.cxdximport()

        cxsq.ConfirmDialog()#获取提示细信息
        cxsq.CreatWs()
        cxsq.ConfirmDialog()#获取提示细信息
        cxsq.dosend()
        cxsq.ConfirmDialog()  # 获取提示细信息
    #     # driver.switch_to.default_content()
    #     # frame = driver.find_element(By.NAME, 'iframe')
    #     # driver.switch_to.frame(frame)
    #     # driver.find_element(By.XPATH,'//input[@value="保存"]').click()
    #     driver.implicitly_wait(2)
    #     print(driver.window_handles)





    # def test_alert(self):  #保存后的 遮罩确认
    #     # a = driver.switch_to.alert()

        # formframe=driver.find_element(By.XPATH,'//*[@id="win_detail"]')
        # driver.switch_to.frame(formframe)
        # print(driver.find_element(By.XPATH,'//*[@id="ext-comp-1001"]/tbody/tr[2]/td[2]'))  #   //*[@id="ext-gen28"]/text()[2]  //*[@id="ext-comp-1001"]/tbody/tr[2]/td[2]
        # driver.find_element(By.XPATH, '//*[@id="ext-comp-1001"]/tbody/tr[2]/td[2]').click()  #点击按钮



    #     driver.find_element(By.XPATH, '//*[@id="ext-comp-1001"]/tbody/tr[2]/td[2]/em').click() #点击按钮  同上
        # a=driver.find_element(By.XPATH, '//*[@id="ext-comp-1001"]/tbody/tr[2]/td[2]/em/button') #点击按钮  同上
        # a = driver.find_element(By.XPATH, '//span[@id="ext-gen28"]')

        # print(a.text)

        # a=driver.find_element(By.XPATH,'//*[@id="ext-comp-1001"]/tbody/tr[2]/td[2] ') #//*[@id="ext-comp-1001"]/tbody/tr[2]/td[2]    //button[@type="button" and text()="确定"]
        # a.click()


        # frame=driver.find_element(By.NAME,'iframe')   #By.XPATH,'//*[@id="ext-gen111"]'
        # print(driver.switch_to.frame(frame))
        # formframe=driver.find_element(By.XPATH,'//*[@id="win_detail"]')
        # driver.switch_to.frame(formframe)
        # driver.find_element(By.XPATH,'//span[@title="选择对象"]').click()
        # driver.find_element(By.XPATH,'//input[@value="保存"]').click()

